package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.ex.ServiceException;
import cn.tedu.csmall.product.pojo.dto.AlbumAddNewDTO;
import cn.tedu.csmall.product.pojo.vo.AlbumListItemVO;
import cn.tedu.csmall.product.service.IAlbumService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 处理相册数据相关请求的控制器
 *
 * @author stephen
 * @version 0.0.1
 */
@Slf4j
@RestController
@RequestMapping("/albums") //再类上添加@RequestMapping("/album")注解，则本类只能处理请求路径为/album/...的请求
@Api(tags = "04.相册管理模块")
//@Controller
//@ResponseBody
public class AlbumController {

    @Autowired
    private IAlbumService albumService;

    public AlbumController(){
        log.info("创建控制器：AlbumController");
    }

    //http://localhost:9080/albums/add-new
    @PostMapping("/add-new")
    @ApiOperation("添加相册")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(@Validated AlbumAddNewDTO albumAddNewDTO) {
        log.info("开始处理【添加相册】请求{}", albumAddNewDTO);
        albumService.addNew(albumAddNewDTO);
        return JsonResult.ok();
    }

    //http://localhost:9080/albums/deleteById
    @PostMapping("/{id:[0-9]+}/deleteById")
    @ApiImplicitParam(name = "id",value = "相册名称",dataType = "Long",required = true)
    @ApiOperation("根据id删除相册")
    @ApiOperationSupport(order = 200)
    public String deleteById(@PathVariable Long id){
        log.info("开始处理【删除相册】请求，id={}",id);
        albumService.deleteById(id);
        return "删除相册成功";
    }


    @ApiOperation("查询相册列表")
    @ApiOperationSupport(order = 300)
    @GetMapping("/list")
    public JsonResult<List<AlbumListItemVO>> list(){
        List<AlbumListItemVO> albumListItem = albumService.listData();
        return JsonResult.ok(albumListItem);
    }




    /*
    //http://localhost:9080/album/a
    //http://localhost:9080/album/aa
    //http://localhost:9080/album/aaa  这三个路径都可以导致xx()方法的启动执行（实际情况只配置一个即可）
    @RequestMapping(value = {"/a","/aa","/aaa"})
    public String xx(AlbumAddNewDTO albumAddNewDTO){
        log.info("开始处理请求{}" ,albumAddNewDTO);
        return "<h1>hello,Spring MVC aaaa</h1>";
    }

    //http://localhost:9080/album/9527/delete
    @RequestMapping("/{id:[0-9]+}/delete")
    public String delete(@PathVariable Long id){
        log.debug("开始处理删除id={}请求",id);
        return "处理了/"+id+"/delete的请求";
    }
    //http://localhost:9080/album/9527/delete
    @RequestMapping("/{name:[a-zA-Z]+}/delete")
    public String delete(@PathVariable String name){
        log.debug("开始处理删除name={}请求",name);
        return "处理了/"+name+"/delete的请求";
    }
    //http://localhost:9080/album/9527/delete
    @RequestMapping("/test/delete")
    public String delete(){
        log.debug("开始处理删除test请求");
        return "处理了/tset/delete的请求";
    }



    //http://localhost:9080/
    @RequestMapping("/b")
    public String xxx(){
        log.info("开始处理请求....");
        return "<h1>hello,Spring MVC bbbb</h1>";
    }

     */
}
